package com.fr.web.platform;

import com.fr.base.FCloneable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.DateUtils;
import com.fr.base.core.json.JSONArray;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.report.cellElement.Formula;
import com.fr.report.parameter.Parameter;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TransmitParameters
  implements FCloneable
{
  public static final String STRING = "String";
  public static final String INTEGER = "Integer";
  public static final String DOUBLE = "Double";
  public static final String DATE = "Date";
  public static final String BOOLEAN = "Boolean";
  public static final String FORMULA = "Formula";
  private List parameterList = new ArrayList();

  public TransmitParameters()
  {
  }

  public TransmitParameters(Parameter[] paramArrayOfParameter)
  {
    for (int i = 0; i < paramArrayOfParameter.length; ++i)
      add(paramArrayOfParameter[i]);
  }

  public JSONArray createJSON()
    throws JSONException
  {
    JSONArray localJSONArray = new JSONArray();
    for (int i = 0; i < size(); ++i)
    {
      JSONObject localJSONObject = new JSONObject();
      Parameter localParameter = get(i);
      localJSONObject.put("name", localParameter.getName());
      if (localParameter.getValue() instanceof Date)
      {
        str = DateUtils.DATEFORMAT2.format(localParameter.getValue());
        localJSONObject.put("value", str);
      }
      else
      {
        localJSONObject.put("value", localParameter.getValue());
      }
      String str = localParameter.getValue().getClass().getName();
      int j = str.lastIndexOf(46) + 1;
      if (j > 0)
        str = str.substring(j);
      localJSONObject.put("type", str);
      localJSONArray.put(localJSONObject);
    }
    return localJSONArray;
  }

  public static TransmitParameters parseJSON(JSONArray paramJSONArray)
    throws JSONException
  {
    TransmitParameters localTransmitParameters = new TransmitParameters();
    for (int i = 0; i < paramJSONArray.length(); ++i)
    {
      JSONObject localJSONObject = paramJSONArray.getJSONObject(i);
      Parameter localParameter = new Parameter();
      localParameter.setName(localJSONObject.getString("name"));
      String str1 = localJSONObject.getString("type");
      if ("String".equals(str1))
      {
        localParameter.setValue(localJSONObject.getString("value"));
      }
      else if ("Integer".equals(str1))
      {
        localParameter.setValue(Integer.valueOf(localJSONObject.getString("value")));
      }
      else if ("Double".equals(str1))
      {
        localParameter.setValue(Double.valueOf(localJSONObject.getString("value")));
      }
      else if ("Date".equals(str1))
      {
        String str2 = localJSONObject.getString("value");
        try
        {
          localParameter.setValue(DateUtils.DATEFORMAT2.parse(str2));
        }
        catch (ParseException localParseException)
        {
          localParseException.printStackTrace();
        }
      }
      else if ("Boolean".equals(str1))
      {
        localParameter.setValue(Boolean.valueOf(localJSONObject.getBoolean("value")));
      }
      else if ("Formula".equals(str1))
      {
        localParameter.setValue(new Formula(localJSONObject.getString("value")));
      }
      localTransmitParameters.add(localParameter);
    }
    return localTransmitParameters;
  }

  public int size()
  {
    return this.parameterList.size();
  }

  public Parameter[] toArray()
  {
    return ((Parameter[])this.parameterList.toArray(new Parameter[this.parameterList.size()]));
  }

  public Parameter get(int paramInt)
  {
    return ((Parameter)this.parameterList.get(paramInt));
  }

  public void add(Parameter paramParameter)
  {
    this.parameterList.add(paramParameter);
  }

  public void set(int paramInt, Parameter paramParameter)
  {
    this.parameterList.set(paramInt, paramParameter);
  }

  public void clear()
  {
    this.parameterList.clear();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof TransmitParameters))
      return false;
    TransmitParameters localTransmitParameters = (TransmitParameters)paramObject;
    return ComparatorUtils.equals(this.parameterList, localTransmitParameters.parameterList);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    int i;
    TransmitParameters localTransmitParameters = (TransmitParameters)super.clone();
    if (this.parameterList != null)
    {
      localTransmitParameters.parameterList = new ArrayList();
      for (i = 0; i < this.parameterList.size(); ++i)
      {
        Object localObject = this.parameterList.get(i);
        if (localObject instanceof FCloneable)
          localObject = ((FCloneable)localObject).clone();
        localTransmitParameters.parameterList.add(localObject);
      }
    }
    return localTransmitParameters;
  }
}